home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Topik / Topik - Disk 03 - Games (19xx)(Topik Public Domain)(PD)[WB].zip / Topik - Disk 03 - Games (19xx)(Topik Public Domain)(PD)[WB].adf / Bluemoon / BlueMoon.c < prev    next >
C/C++ Source or Header  |  1989-05-26  |  17KB  |  630 lines

  1. /* Bluemoon - solitaire card game...ported to the Amiga by Tony Vallot */
  2. /* A sloppy hack but a good learning experience....                    */
  3. /* Unix text version released to USENET by Tim Lister                  */
  4. /* Compiles under Manx 3.6a 'cc BlueMoon.c ... ln +c BlueMoon.o -lc'   */
  5. /*                                       the +c forces chip loading    */
  6. /* This program falls under the shareware category. Contributions      */
  7. /* would be appreciated... have fun!                                   */
  8. /*                                                                     */
  9. /*          Tony Vallot                                                */
  10. /*          1211 Bancroft Street #3                                    */
  11. /*          Bellingham, WA 98225                                       */
  12. /*                                                                     */
  13. #include <functions.h>
  14. #include <exec/types.h>
  15. #include <graphics/gfxbase.h>
  16. #include <intuition/intuition.h>
  17.  
  18. struct IntuitionBase   *IntuitionBase;
  19. struct GfxBase         *GfxBase;
  20. struct Screen          *screen;
  21. struct Window          *window;
  22. struct RastPort        *rastport;
  23. struct ViewPort        *viewport;
  24.  
  25. ULONG  class;          /* Mouse info vars */
  26. SHORT  mouseX, mouseY, mousedown, newgame, quit;
  27. char   bmout[]    = { "Blue Moon - by Tim Lister - Deal Number #" };
  28. char   numdeals[] = { "You finished the game in # deals." };
  29. char   cardlett[] = { "A 2 3 4 5 6 7 8 9 10J Q K " };
  30.  
  31. #define Q_MINX  40L
  32. #define Q_MINY 187L
  33. #define Q_MAXX 128L
  34. #define Q_MAXY 199L
  35.  
  36. #define N_MINX 512L
  37. #define N_MINY 187L
  38. #define N_MAXX 600L
  39. #define N_MAXY 199L
  40.  
  41. struct NewScreen newscreen = {
  42.    0, 0, 640, 200, 2, 0, 1, HIRES, CUSTOMSCREEN,  NULL, NULL, NULL, NULL };
  43.  
  44. struct NewWindow newwindow = {
  45.    0, 0, 640, 200, 0, 1, MOUSEBUTTONS, BACKDROP | BORDERLESS,
  46.    NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, CUSTOMSCREEN };
  47.  
  48. USHORT acard [] = {
  49.    0x7fff, 0xfffe, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
  50.    0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
  51.    0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
  52.    0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
  53.    0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
  54.    0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x7fff, 0xfffe };
  55.  
  56. USHORT nocard[] = {
  57.    0x7fff, 0xfffe, 0x8000, 0x0001, 0x8000, 0x0001, 0x8000, 0x0001,
  58.    0x8000, 0x0001, 0x8000, 0x0001, 0x8000, 0x0001, 0x8000, 0x0001,
  59.    0x8000, 0x0001, 0x8000, 0x0001, 0x8000, 0x0001, 0x8000, 0x0001,
  60.    0x8000, 0x0001, 0x8000, 0x0001, 0x8000, 0x0001, 0x8000, 0x0001,
  61.    0x8000, 0x0001, 0x8000, 0x0001, 0x8000, 0x0001, 0x8000, 0x0001,
  62.    0x8000, 0x0001, 0x8000, 0x0001, 0x8000, 0x0001, 0x7fff, 0xfffe };
  63.  
  64. USHORT selected[] = {
  65.    0x3fff, 0xffff, 0xfc00,
  66.    0x7fff, 0xffff, 0xfe00,
  67.    0x7800, 0x0000, 0x1e00,
  68.    0x7000, 0x0000, 0x0e00,
  69.    0x7000, 0x0000, 0x0e00,
  70.    0x7000, 0x0000, 0x0e00,
  71.    0x7000, 0x0000, 0x0e00,
  72.    0x7000, 0x0000, 0x0e00,
  73.    0x7000, 0x0000, 0x0e00,
  74.    0x7000, 0x0000, 0x0e00,
  75.    0x7000, 0x0000, 0x0e00,
  76.    0x7000, 0x0000, 0x0e00,
  77.    0x7000, 0x0000, 0x0e00,
  78.    0x7000, 0x0000, 0x0e00,
  79.    0x7000, 0x0000, 0x0e00,
  80.    0x7000, 0x0000, 0x0e00,
  81.    0x7000, 0x0000, 0x0e00,
  82.    0x7000, 0x0000, 0x0e00,
  83.    0x7000, 0x0000, 0x0e00,
  84.    0x7000, 0x0000, 0x0e00,
  85.    0x7000, 0x0000, 0x0e00,
  86.    0x7000, 0x0000, 0x0e00,
  87.    0x7000, 0x0000, 0x0e00,
  88.    0x7000, 0x0000, 0x0e00,
  89.    0x7000, 0x0000, 0x0e00,
  90.    0x7800, 0x0000, 0x1e00,
  91.    0x7fff, 0xffff, 0xfe00,
  92.    0x3fff, 0xffff, 0xfc00 };
  93.  
  94. /* someone could really make these look better... */
  95. USHORT heart[] = {
  96.    0x0000, 0x0000, 0x03f0, 0x0fc0, 0x0ffe, 0x7ff0, 0x1ffe, 0x7ff8,
  97.    0x1fff, 0xfff8, 0x1fff, 0xfff8, 0x1fff, 0xfff8, 0x0fff, 0xfff0,
  98.    0x07ff, 0xffe0, 0x00ff, 0xff00, 0x001f, 0xf800, 0x0007, 0xe000,
  99.    0x0001, 0x8000, 0x0000, 0x0000 };
  100.  
  101. USHORT diamond[] = {
  102.    0x0000, 0x0000, 0x0001, 0x8000, 0x0003, 0xc000, 0x000f, 0xf000,
  103.    0x001f, 0xf800, 0x007f, 0xfe00, 0x01ff, 0xff80, 0x01ff, 0xff80,
  104.    0x007f, 0xfe00, 0x001f, 0xf800, 0x000f, 0xf000, 0x0007, 0xc000,
  105.    0x0001, 0x8000, 0x0000, 0x0000 };
  106.  
  107. USHORT spade[] = {
  108.    0x0000, 0x0000, 0x0001, 0x8000, 0x0007, 0xe000, 0x003f, 0xfc00,
  109.    0x00ff, 0xff00, 0x03ff, 0xffc0, 0x07ff, 0xffe0, 0x0fff, 0xfff0,
  110.    0x1fff, 0xfff8, 0x1ffd, 0xbff8, 0x0ff9, 0x9ff0, 0x07f3, 0xcfe0,
  111.    0x0007, 0xe000, 0x0000, 0x0000 };
  112.  
  113. USHORT club[] = {
  114.    0x0000, 0x0000, 0x0003, 0xc000, 0x001f, 0xf800, 0x003f, 0xfc00,
  115.    0x003f, 0xfc00, 0x001f, 0xf800, 0x01cf, 0xf380, 0x0fff, 0xfff0,
  116.    0x1fff, 0xfff8, 0x1ffd, 0xbff8, 0x1ffd, 0xbff8, 0x0ffb, 0xdff0,
  117.    0x01e7, 0xe780, 0x0000, 0x0000 };
  118.  
  119. USHORT *suitptr[] = { heart, spade, diamond, club };
  120.  
  121. #define BACKGROUND 0L
  122. #define WHITE      1L
  123. #define BLACK      2L
  124. #define RED        3L
  125.  
  126. openall()
  127. {
  128.    if (!(IntuitionBase = (struct IntuitionBase *)
  129.       OpenLibrary ("intuition.library", 0L))) {
  130.       printf ("No Intuition!\n");
  131.       exit (FALSE);
  132.    }
  133.    if (!(GfxBase = (struct GfxBase *)
  134.       OpenLibrary ("graphics.library", 0L))) {
  135.       printf ("No Graphics!\n");
  136.       exit (FALSE);
  137.    }
  138.    if (!(screen = OpenScreen (&newscreen))) {
  139.       printf ("No Screen!\n");
  140.       exit (FALSE);
  141.    }
  142.    newwindow.Screen = screen;
  143.    if (!(window = OpenWindow (&newwindow))) {
  144.       printf ("No Window!\n");
  145.       exit (FALSE);
  146.    }
  147. }
  148.  
  149. my_init()
  150. {
  151.    openall ();
  152.    viewport = (struct ViewPort *) ViewPortAddress (window);
  153.    rastport = &(screen->RastPort);
  154.    SetDrMd (rastport, JAM1);
  155.    SetAPen (rastport, WHITE);
  156.    SetBPen (rastport, BACKGROUND);
  157.    mousedown = FALSE;
  158.    quit = FALSE;
  159. }
  160.  
  161. closeall ()
  162. {
  163.    if (window)        CloseWindow  (window);
  164.    if (screen)        CloseScreen  (screen);
  165.    if (GfxBase)       CloseLibrary (GfxBase);
  166.    if (IntuitionBase) CloseLibrary (IntuitionBase);
  167.    exit (TRUE);
  168. }
  169.  
  170. centerprint (x, y, str, col)
  171. long x, y;
  172. char str[];
  173. long col;
  174. {
  175.    long len, numpixels;
  176.  
  177.    len = strlen (str);
  178.    if (col != WHITE)
  179.       SetAPen (rastport, col);
  180.    numpixels = TextLength (rastport, str, len);
  181.    x = x - (numpixels / 2L);
  182.    Move (rastport, x, y);
  183.    Text (rastport, str, len);
  184.    if (col != WHITE)
  185.       SetAPen (rastport, WHITE);
  186. }
  187.  
  188. offcenterprint (x, y, str, frontcol, backcol)
  189. long x, y;
  190. char str[];
  191. long frontcol, backcol;
  192. {
  193.    centerprint (x+1L, y+1L, str, backcol);
  194.    centerprint (x, y, str, frontcol);
  195. }
  196.  
  197. /*****************************************************************************
  198.  *                                                                           *
  199.  *                         B l u e   M o o n                                 *
  200.  *                         =================                                 *
  201.  *                                                                           *
  202.  *                  A patience game by T.A.Lister                            *
  203.  *                                                                           *
  204.  *****************************************************************************/
  205.  
  206. #include <stdio.h>
  207.  
  208. #define NOCARD      -1
  209.  
  210. #define HEARTS      0
  211. #define SPADES      1
  212. #define DIAMONDS   2
  213. #define CLUBS      3
  214.  
  215. #define ACE      0
  216. #define TWO      1
  217. #define THREE      2
  218. #define FOUR      3
  219. #define FIVE      4
  220. #define SIX      5
  221. #define SEVEN      6
  222. #define EIGHT      7
  223. #define NINE      8
  224. #define TEN      9
  225. #define JACK      10
  226. #define QUEEN      11
  227. #define KING      12
  228.  
  229. #define SUIT_LENGTH   13
  230.  
  231. #define GRID_WIDTH   14   /*    13+1  */
  232. #define GRID_LENGTH   56   /* 4*(13+1) */
  233. /*convert grid # to actual screen coordinates */
  234. #define convertX(x) (x % GRID_WIDTH) * 40 + 45
  235. #define convertY(y) ((y / GRID_WIDTH) * 30) + ((y / GRID_WIDTH) * 5) + 20
  236.  
  237. #define PACK_SIZE   52
  238.  
  239. int deck_size=PACK_SIZE;   /* initial deck */
  240. int deck[PACK_SIZE];
  241.  
  242. int grid[GRID_LENGTH];   /* card layout grid */
  243. int freeptr[4];      /* free card space pointers */
  244.  
  245. int deal_number;
  246.  
  247. init_vars()
  248. {
  249.    int i;
  250.  
  251.    deal_number=0;
  252.    deck_size=PACK_SIZE;
  253.    for(i=0;i<PACK_SIZE;i++)   deck[i]=i;
  254.    for(i=0;i<4;i++)      freeptr[i]=i * GRID_WIDTH;
  255. }
  256.  
  257. shuffle(size)
  258. int size;
  259. {
  260.    int i,j,numswaps,swapnum,temp;
  261.  
  262.    numswaps=size*10;   /* an arbitrary figure */
  263.  
  264.    for (swapnum=0;swapnum<numswaps;swapnum++)
  265.    {
  266.       i=rand() % size;
  267.       j=rand() % size;
  268.       temp=deck[i];
  269.       deck[i]=deck[j];
  270.       deck[j]=temp;
  271.    }
  272. }
  273.  
  274. deal_cards()
  275. {
  276.    int ptr, card=0, value, csuit, crank, suit, aces[4];
  277.  
  278.    for (suit=HEARTS;suit<=CLUBS;suit++)
  279.    {
  280.       ptr=freeptr[suit];
  281.       grid[ptr++]=NOCARD;   /* 1st card space is blank */
  282.       while ((ptr % GRID_WIDTH) != 0)
  283.       {
  284.          value=deck[card++];
  285.          crank=value % SUIT_LENGTH;
  286.          csuit=value / SUIT_LENGTH;
  287.          if (crank==ACE)
  288.             aces[csuit]=ptr;
  289.          grid[ptr++]=value;
  290.       }
  291.    }
  292.  
  293.    if (deal_number==1)   /* shift the aces down to the 1st column */
  294.       for (suit=HEARTS;suit<=CLUBS;suit++)
  295.       {
  296.          grid[suit * GRID_WIDTH] = suit * SUIT_LENGTH;
  297.          grid[aces[suit]]=NOCARD;
  298.          freeptr[suit]=aces[suit];
  299.       }
  300. }
  301.  
  302. printcard(cd) /* altered a bit ... TV */
  303. int cd;
  304. {
  305.    long x, y;
  306.    int rank, suit;
  307.    char out;
  308.  
  309.    x = convertX(cd);
  310.    y = convertY(cd);
  311.    rank=grid[cd] % SUIT_LENGTH;
  312.    suit=grid[cd] / SUIT_LENGTH;
  313.  
  314.    if (rank == NOCARD) {
  315.       SetDrMd (rastport, JAM2);
  316.       BltTemplate (&nocard[0], 0L, 4L, rastport, x, y, 32L, 24L);
  317.       SetDrMd (rastport, JAM1); /* restore normal drawing mode */
  318.    }
  319.    else {
  320.       BltTemplate (&acard[0], 0L, 4L, rastport, x, y, 32L, 24L);
  321.  
  322.       SetAPen (rastport, (suit % 2) ? BLACK : RED); /* put suit symbol */
  323.       BltTemplate (suitptr[suit], 0L, 4L, rastport, x, y+10L, 32L, 14L);
  324.  
  325.       Move (rastport, x+2L, y+7L); /* and draw the rank */
  326.       Text (rastport, &cardlett[rank*2], 2L);
  327.  
  328.       SetAPen (rastport, WHITE); /* restore default pen */
  329.    }
  330. }
  331.  
  332. show_select (cd, col) /* TV */
  333. int cd;
  334. long col;
  335. {
  336.    long x, y;
  337.  
  338.    x = convertX(cd);
  339.    y = convertY(cd);
  340.  
  341.    SetAPen (rastport, col);
  342.    BltTemplate (selected, 0L, 6L, rastport, x-4L, y-2L, 48L, 28L);
  343.    SetAPen (rastport, WHITE);
  344. }
  345.  
  346. coloroff ()
  347. {
  348.    SetRGB4 (viewport, 0L,  0L,  2L, 10L);
  349.    SetRGB4 (viewport, 1L,  0L,  2L, 10L);
  350.    SetRGB4 (viewport, 2L,  0L,  2L, 10L);
  351.    SetRGB4 (viewport, 3L,  0L,  2L, 10L);
  352. }
  353.  
  354. coloron ()
  355. {
  356.    SetRGB4 (viewport, 1L, 15L, 15L, 15L);
  357.    SetRGB4 (viewport, 2L,  0L,  0L,  0L);
  358.    SetRGB4 (viewport, 3L, 15L,  1L,  3L);
  359. }
  360.  
  361. makebox (minx, miny, maxx, maxy, st)
  362. long minx, miny, maxx, maxy;
  363. char st[];
  364. {
  365.    long x, y;
  366.  
  367.    RectFill (rastport, minx, miny, maxx, maxy);  /* Make the box */
  368.    minx = minx + 2; miny++; maxx = maxx - 2; maxy--;
  369.    SetAPen (rastport, RED); /* Draw a border in it */
  370.    Move (rastport, minx, miny);
  371.    Draw (rastport, maxx, miny);
  372.    Draw (rastport, maxx, maxy);
  373.    Draw (rastport, minx, maxy);
  374.    Draw (rastport, minx, miny);
  375.    Draw (rastport, maxx, miny);
  376.    SetAPen (rastport, WHITE);
  377.  
  378.    x = ((maxx-minx) / 2L) + minx; /* Put text in it */
  379.    y = ((maxy-miny) / 2L) + miny + 3L;
  380.    centerprint (x, y, st, BLACK);
  381. }
  382.  
  383. display_cards(deal)
  384. int deal;
  385. {
  386.    int row, card; /* More alteration...TV */
  387.  
  388.    coloroff();
  389.    SetRast (rastport, BACKGROUND);
  390.  
  391.    bmout[40] = (char) (deal + 48);
  392.    offcenterprint (320L, 10L, bmout, WHITE, BLACK);
  393.  
  394.    makebox (Q_MINX, Q_MINY, Q_MAXX, Q_MAXY, "* Quit *");
  395.    makebox (N_MINX, N_MINY, N_MAXX, N_MAXY, "New Game");
  396.  
  397.    for(row=HEARTS;row<=CLUBS;row++)
  398.       for(card=0;card<GRID_WIDTH;card++)
  399.          printcard(row * GRID_WIDTH + card);
  400.  
  401.    centerprint (320L, 160L, "Select card to move", WHITE);
  402.    offcenterprint (320L, 195L, "AMIGAized by AG Vallot", RED, BLACK);
  403.  
  404.    coloron();
  405. }
  406.  
  407. find(card)
  408. int card;
  409. {
  410.    int i;
  411.  
  412.    if ((card<0)||(card>=PACK_SIZE))   return NOCARD;
  413.    for(i=0;i<GRID_LENGTH;i++)
  414.       if (grid[i]==card)      return i;
  415.    return NOCARD;
  416. }
  417.  
  418. movecard(src, dst) /* etc */
  419. int src, dst;
  420. {
  421. /*   show_select (src, BACKGROUND); */
  422.    grid[dst]=grid[src];
  423.    grid[src]=NOCARD;
  424.  
  425.    printcard(dst);
  426.    printcard(src);
  427. }
  428.  
  429. inrange (minx, maxx, miny, maxy)
  430. long minx, maxx, miny, maxy;
  431. {
  432.    if ((mouseX>=minx) && (mouseX<=maxx) && (mouseY>=miny) && (mouseY<=maxy))
  433.       return (TRUE);
  434.    else
  435.       return (FALSE);
  436. }
  437.  
  438. domouse ()
  439. {
  440.    struct IntuiMessage *mes;
  441.  
  442.    while ((mes = (struct IntuiMessage *) GetMsg(window->UserPort)) == NULL)
  443.       Wait (1L << window->UserPort->mp_SigBit);
  444.    class  = mes->Class;
  445.    mouseX = mes->MouseX;
  446.    mouseY = mes->MouseY;
  447.    ReplyMsg (mes);
  448.  
  449.    if (class == MOUSEBUTTONS)
  450.       mousedown = !mousedown;
  451.    if (mousedown) {
  452.       if (inrange(Q_MINX, Q_MAXX, Q_MINY, Q_MAXY)) /* quit */
  453.          quit = TRUE;
  454.       else if (inrange(N_MINX, N_MAXX, N_MINY, N_MAXY)) /* new game */
  455.          newgame = TRUE;
  456.    }
  457. }
  458.  
  459. char checkmouse (s) /* TV */
  460. int s[];
  461. {
  462.    SHORT  i;
  463.    long tx, ty;
  464.    char ret;
  465.  
  466.    ret = NOCARD;
  467.    domouse();
  468.    if ((class == MOUSEBUTTONS) && (mousedown)) {
  469.       if (quit)
  470.          ret = 'q';
  471.       else if (newgame)
  472.          ret = 'n';
  473.       else
  474.          for (i=0; i<4; i++)
  475.             if (s[i] != NOCARD) {
  476.                tx = convertX(s[i]);
  477.                ty = convertY((long) s[i]);
  478.                if (inrange (tx, tx+32L, ty, ty+24L))
  479.                   ret = (i+'a');
  480.             }
  481.    }
  482.    return (ret);
  483. }
  484.  
  485. play_game() /* etc... */
  486. {
  487.    int dead=0, i, j, found;
  488.    char c;
  489.    int select[4], oldselect[4], card;
  490.  
  491.    for (i=0; i<4; i++)
  492.       oldselect[i] = NOCARD;
  493.    while ((dead<4) && (!newgame) && (!quit))
  494.    {
  495.       dead=0;
  496.       for (i=0;i<4;i++)
  497.       {
  498.          card=grid[freeptr[i]-1];
  499.  
  500.          if (((card % SUIT_LENGTH) == KING) || (card == NOCARD))
  501.             select[i]=NOCARD;
  502.          else
  503.             select[i]=find(card+1);
  504.  
  505.          if (select[i]==NOCARD)
  506.             dead++;
  507.       };
  508.  
  509.       if (dead<4)
  510.       {
  511.          /* these next two fors are here simply to keep from drawing boxes
  512.             that are already drawn and erasing boxes that dont need it...
  513.             gets rid of that ugly flash...but adds ugly code ;-) */
  514.          for (i=0;i<4;i++)
  515.             if (select[i]!=NOCARD) {
  516.                for (found=FALSE, j=0; j<4; j++)
  517.                   if ((oldselect[j]!=NOCARD) && (select[i]==oldselect[j])) {
  518.                      oldselect[j] = NOCARD;
  519.                      found=TRUE;
  520.                   }
  521.                if (!found)
  522.                   show_select (select[i], RED);
  523.             }
  524.          for (i=0; i<4; i++)
  525.             if (oldselect[i]!=NOCARD)
  526.                show_select(oldselect[i], BACKGROUND);
  527.  
  528.          c = NOCARD;
  529.          while ( ( (c<'a') || (c>'d') ) && (c!='q') && (c!='n'))
  530.             c = checkmouse (select);
  531.  
  532.          if ((c!='q')&&(c!='n')) {
  533.             i=c-'a';
  534.             if (select[i]!=NOCARD)
  535.             {
  536.                movecard(select[i], freeptr[i]);
  537.                freeptr[i]=select[i];
  538.             }
  539.          }
  540.          for(i=0; i<4; i++)
  541.             oldselect[i] = select[i];
  542.       }
  543.    }
  544.    for (i=0; i<4; i++) /* clean up screen (all excess select boxes) */
  545.       if (oldselect[i]!=NOCARD)
  546.          show_select(oldselect[i], BACKGROUND);
  547. }
  548.  
  549. my_continue () /* TV */
  550. {
  551.    centerprint (320L, 160L, "Select card to move", BACKGROUND);
  552.    centerprint (320L, 170L,
  553.       "*** New Deal - Hit Left Mouse Button to Continue ***", WHITE);
  554.    domouse();
  555. }
  556.  
  557. game_finished(deal) /* etc.. */
  558. int deal;
  559. {
  560.    centerprint (320L, 160L, "Select card to move", BACKGROUND);
  561.  
  562.    numdeals[25] = (char) (deal + 48);
  563.    centerprint (320L, 165L, numdeals, WHITE);
  564.  
  565.    if (deal<4)
  566.       centerprint (320L, 175L, "This is good.", WHITE);
  567.    else if (deal<8)
  568.       centerprint (320L, 175L, "This is average.", WHITE);
  569.    else
  570.       centerprint (320L, 175L, "This is poor.", WHITE);
  571.  
  572.    while (!(quit || newgame))
  573.       domouse ();
  574. }
  575.  
  576. collect_discards(dn) /* only slightly altered etc.. TV */
  577. int dn;
  578. {
  579.    int row, col, cardno=0, finish, gridno;
  580.  
  581.    if ((newgame) || (quit))
  582.       return (0);
  583.    else for (row=HEARTS;row<=CLUBS;row++) {
  584.       finish=0;
  585.       for (col=1;col<GRID_WIDTH;col++)
  586.       {
  587.          gridno=row * GRID_WIDTH + col;
  588.  
  589.          if ((grid[gridno]!=(grid[gridno-1]+1))&&(finish==0))
  590.          {
  591.             finish=1;
  592.             freeptr[row]=gridno;
  593.          };
  594.  
  595.          if ((finish!=0)&&(grid[gridno]!=NOCARD))
  596.             deck[cardno++]=grid[gridno];
  597.       }
  598.    }
  599.    domouse(); /* get last mouseup */
  600.    if (cardno != 0)
  601.       my_continue();
  602.    else
  603.       game_finished (dn);
  604.    if ((newgame) || (quit))
  605.       return (0);
  606.    else
  607.       return cardno;
  608. }
  609.  
  610. main() /* Yep... this one too... */
  611. {
  612.    my_init ();
  613.  
  614.    srand((int)time((long *)0));
  615.  
  616.    while (!quit) {
  617.       init_vars();
  618.       newgame = FALSE;
  619.  
  620.       do{
  621.          deal_number++;
  622.          shuffle(deck_size);
  623.          deal_cards();
  624.          display_cards(deal_number);
  625.          play_game();
  626.       }while ((deck_size=collect_discards(deal_number)) != 0);
  627.    }
  628.    closeall();
  629. }
  630.